import javax.swing.*;

/**
 * ****************************************************************************
 * $Author: Yegor Chemisov $
 * $Revision: 1.4 $
 * ****************************************************************************
 */

public class Cards
{
    private final static String IMAGES_CATALOGUE  = "/images/";
    private final static String IMAGES_EXTENTION  = ".gif";
    private final static String[] FILES     = { "back", "2c", "2d", "2h", "2s", "3c", "3d",
                       "3h", "3s", "4c", "4d", "4h", "4s", "5c", "5d", "5h", "5s", "6c", "6d",
                       "6h", "6s", "7c", "7d", "7h", "7s", "8c", "8d", "8h", "8s", "9c", "9d",
                       "9h", "9s", "tc", "td", "th", "ts", "jc", "jd", "jh", "js", "qc", "qd",
                       "qh", "qs", "kc", "kd", "kh", "ks", "ac", "ad", "ah", "as" };

    static private ImageIcon[] images  = new ImageIcon[MAPConsts.NUM_IMAGES + 1];

    public Cards()
    {
        if (images[0] == null)
            loadImages();
    }

    public ImageIcon getBackImage()
    {
        return images[0];
    }

    public ImageIcon getImageAt(int i)
    {
        return images[i];
    }
    private void loadImages()
    {
        //Get the images and put them into an array of ImageIcons.
        for (int i = 0; i <= MAPConsts.NUM_IMAGES; i++)
        {
            images[i] = createImageIcon(IMAGES_CATALOGUE +
                    FILES[i] + IMAGES_EXTENTION);
        }
    }

    /** Returns an ImageIcon, or null if the path was invalid. */
    private static ImageIcon createImageIcon(String path) {
        java.net.URL imageURL = Cards.class.getResource(path);

        if (imageURL == null) {
            System.err.println("Resource not found: " + path);
            return null;
        } else {
            return new ImageIcon(imageURL);
        }
    }
}
